package me.zhengjie.modules.system.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.Contract;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.modules.system.domain.UserInfo;
import me.zhengjie.modules.system.service.UserInfoService;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用戶信息")
@RestController
@RequestMapping("/api/userinfo")
@RequiredArgsConstructor
public class UserInfoController {

    private final UserInfoService userInfoService;

    @ApiOperation("查询客戶信息-通过Id查询")
    @PostMapping
    public ResponseEntity<Object> selectUserInfos(@RequestBody UserInfo userInfo){
        UserInfo result = userInfoService.fandByUserCondition(userInfo.getUserId());
        return new ResponseEntity<>(result,HttpStatus.OK);
    }

    @ApiOperation("查询客戶信息-条件查询")
    @PostMapping(value = "/selectUserInfoList")
    public ResponseEntity<Object> selectUserInfoList(@RequestBody UserInfo userInfo){
        List<UserInfo> result = userInfoService.fandByUserConditionList(userInfo.getUserName(), userInfo.getUserType());
        return new ResponseEntity<>(result,HttpStatus.OK);
    }

    @ApiOperation("客户信息修改")
    @PutMapping
    public ResponseEntity<Object> updateUserInfo(@RequestBody UserInfo userInfo){
        userInfoService.updateUserInfo(userInfo);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @ApiOperation("查看合同信息")
    @GetMapping(value = "/selectContractInfo")
    public ResponseEntity<Object> selectContractInfo(String userInfoId){
        Contract result = userInfoService.selectContractInfo(userInfoId);
        return new ResponseEntity<>(result,HttpStatus.OK);
    }

    @ApiOperation("新增合同信息")
    @PostMapping(value = "/instertContractInfo")
    public ResponseEntity<Object> instertContractInfo(@RequestBody Contract contract){
        userInfoService.saveContractInfo(contract);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @ApiOperation("修改用户审核状态")
    @GetMapping(value = "/updateStatus")
    public ResponseEntity<Object> updateStatus(Integer userInfoId,String userStatus){
        userInfoService.updateStatus(userInfoId,userStatus);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
